<?php

declare(strict_types=1);
/*
 * This file is part of Leonsw.
 *
 * @link     https://leonsw.com
 * @document https://docs.leonsw.com
 * @contact  leonsw.com@gmail.com
 * @license  https://leonsw.com/LICENSE
 */
namespace App\Resource\Activity\Carnival\Info;

use Illuminate\Http\Resources\Json\JsonResource;

class Resource extends JsonResource
{
    public function toArray($request)
    {
        if (empty($this->start_at)) {
            return null;
        }

        $roundSetting = $this->round_setting;
        if (! empty($roundSetting)) {
            $roundSettingData = [
                'start_at'  => $roundSetting->start_at,
                'end_at'    => $roundSetting->end_at,
                'countdown' => $roundSetting->countdown,
                'type'      => $roundSetting->type,
                'score_type'=> $roundSetting->score_type,
                'round'     => $roundSetting->round,
                'groups'    => $roundSetting->groups,
                'count'     => $roundSetting->count,
            ];
        } else {
            $roundSettingData = (object) [];
        }
        return [
            'id'            => $this->id,
            'start_at'      => $this->start_at,
            'end_at'        => $this->end_at,
            'is_close'      => $this->is_close,
            'round_setting' => $roundSettingData
        ];
    }
}
